package Json;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.Since;
import com.google.gson.annotations.Until;

/**
* @author jie
* @version 创建时间：2018年6月13日 上午9:41:48
* 
* 当版本( GsonBuilder 设置的版本) 大于或等于 Since 属性值或小于 Until 属性值时
* 字段会进行序列化和反序列化操作，而没有声明注解的字段都会加入序列化和反序列操作。
*/
public class SinceUtilTest {
	public static void main(String[] args) {
		Gson gson = new GsonBuilder().setVersion(1.6).create();
		User3 user = new User3("A", "B", "C", "D", "E", "F");

		System.err.println(gson.toJson(user));

		String json = "{\"a\":\"A\",\"b\":\"B\",\"c\":\"C\",\"d\":\"D\",\"e\":\"E\",\"f\":\"F\"}";
		user = gson.fromJson(json, User3.class);
		System.out.println();
		System.out.println(user.toString());

	}
}

class User3 {

	@Since(1.4)
	private String a;

	@Since(1.6)
	private String b;

	@Since(1.8)
	private String c;

	@Until(1.6)
	private String d;

	@Until(2.0)
	private String e;
	
	private String f;

	public User3(String a, String b, String c, String d, String e,String f) {
        this.a = a;
        this.b = b;
        this.c = c;
        this.d = d;
        this.e = e;
        this.f=f;
    }

	@Override
	public String toString() {
		return "User [a=" + a + ", b=" + b + ", c=" + c + ", d=" + d + ", e=" + e + ", f=" + f + "]";
	}

}
